<%@page import="com.hamizhong.iflowers.utils.MyConstants"%>
<%@page import="com.hamizhong.iflowers.utils.MyColumnIndicator"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<%@include file="../../common/common_admin.jsp" %>
<title>用户管理</title>
</head>

<script type="text/javascript">
	
	function initUserListByCondition(pageNum) {
		var searchCondition = $('#searchCondition').val();
		$.ajax({
			url: '<%=request.getContextPath() %>/admin/ajaxQueryUsersByCondition.action',
			data: {
				"searchCondition": searchCondition,
				"pageNum": pageNum
			},
			type: 'post',
			async: true,
			dataType: 'json',
			success: function (res) {
				var rs = res.result;
				var totalCnt = res.totalCnt;
				var totalPageCnt = res.totalPageCnt;
				var pageNum = res.pageNum;
				if(rs != 0) {
					var msg = res.msg;
					$('#itemListDiv').html(msg);
					return;
				}else {
					var data = res.data;
					var dataHtml = '';
					if(data.length == 0) {
						dataHtml += '当前条件下暂时没有用户！';
					}else {
						dataHtml += 
						'<table width="100%" border="1px">'+
							'<thead>'+
								'<tr style="font-weight: bold;">'+
									'<td width="60">用户ID</td>'+
									'<td width="100">用户名</td>'+
									'<td width="140">Email</td>'+
									'<td width="100">联系方式</td>'+
									'<td width="100">注册时间</td>'+
									'<td width="100">操作</td>'+
								'</tr>'+
							'</thead>';
						for(var i=0;i<data.length;i++) {
							dataHtml += 
							'<tr>'+
								'<td>'+data[i].userId+'</td>'+
								'<td><a href="javascript: void(0)" onclick="alertUserDetailWindow('+data[i].userId+')">'+data[i].userName+'</a></td>'+
								'<td>'+data[i].userEmail+'</td>'+
								'<td>'+data[i].userPhone+'</td>'+
								'<td>'+data[i].createDate+'</td>'+
								'<td><a href="javascript: void(0);" onclick="alertUserDetailWindow('+data[i].userId+')">修改</a></td>';
						}
						dataHtml += 
						'</tr>';
					}
					dataHtml += '</table>';
				}
				$('#itemListDiv').html(dataHtml);	
				
				/*分页*/
				var pagingHtmlStr = queryPagingModule(pageNum,totalPageCnt,totalCnt);
				$('#pagingDiv').html(pagingHtmlStr);
			}
		});
	}
	
	//跳转到指定页码
	function goTargetPageNum(targetPageNum) {
		initUserListByCondition(targetPageNum);
	}
	function checkToTargetPage(totalPageNum) {
		var inputPageNum = $('#targetPageInput').val();
		//判断是否为空--是否为整数--是否为正数--是否为有效页数内的正整数
		if( isNaN(inputPageNum) || (parseInt(inputPageNum) != inputPageNum) || 
				(Math.abs(parseInt(inputPageNum)) != parseInt(inputPageNum)) ||  (inputPageNum > totalPageNum) || (inputPageNum < 1 )) {
			alert("请输入查询范围内的正整数页码！");
			return;
		}else {
			goTargetPageNum(inputPageNum);
		}
	}
	
	function alertUserDetailWindow(userId) {
		//vReturnValue = window.showModelessDialog(sURL,[vArguments],[sFeatures]);
		//vArguments:可选参数，类型：变体。用来向对话框传递参数。传递的参数类型不限，包括数组等
		//var obj = new Object(); obj.name="testname";
		//对话框通过window.dialogArguments来取得传递进来的参数。
	    var retValue;
		var pageURL = '<%=request.getContextPath() %>/admin/userDetail.action?userId='+userId+'&random='+Math.random();
		var dialogWidth = 800;
		var dialogHeight = 600;
		var dialogTop = (screen.height - dialogHeight)/2;
		var dialogLeft = (screen.width - dialogWidth)/2;
		var params = 'dialogTop:'+dialogTop+'px;dialogLeft:'+dialogLeft+';dialogWidth:'+dialogWidth+'px;dialogHeight:'+dialogHeight+'px;help:no;unadorned:no;resizable:no;status:no;';
		retValue = window.showModalDialog(pageURL,window,params);
	    //弹出窗口通过：window.returnValue="xxx"; 返回值。也可以是对象
	    //alert(retValue);
	}
	
</script>

<body>
	<div class="displayPageHeader">当前位置：用户管理 >> 用户管理</div>
	<div class="pageDiv">
		<div class="pageHeadDiv"><font>用户搜索</font></div>
		<div class="infoDiv">
			<input type="text" id="searchCondition" name="searchCondition"><input type="button" onclick="initUserListByCondition(1)" value="搜索">
		</div>
	</div>
	<div class="pageDiv">
		<div class="pageHeadDiv">结果列表</div>
		<div class="infoDiv">
			<div id="itemListDiv" class="itemListDiv">
				
			</div>
			<div class="margin_5"></div>
			<div id="pagingDiv" style="border: 1px solid #CCC;width: 100%;height: 25px;line-height: 25px;text-align: left;">
				
			</div>
		</div>
	</div>
	<div class="margin_50"></div>
</body>
</html>